/**
 * Copyright (c) 2012, Camelot and/or its affiliates. All rights reserved.
 * Camelot PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.camelot.ccr.system.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.camelot.ccr.global.dao.genericimpl.GenericHibernateDaoImpl;
import com.camelot.ccr.global.util.Pager;
import com.camelot.ccr.global.util.Utility;
import com.camelot.ccr.system.dao.MatchTeamDao;
import com.camelot.ccr.system.persistence.MatchTeam;
import com.camelot.ccr.system.persistence.Team;

/**
 * <pre>
 * 车队信息维护
 * </pre>
 * @author Liu Jun
 * @version V0.1, 2014-5-20 下午10:30:05
 */
@Repository
public class MatchTeamDaoImpl extends GenericHibernateDaoImpl<MatchTeam, String> implements MatchTeamDao {

	/* (non-Javadoc)
	 * @see com.camelot.ccr.system.dao.MatchTeamDao#findPageList(int, com.camelot.ccr.system.persistence.MatchTeam)
	 */
	@Override
	public Pager<MatchTeam> findPageList(int curpage, int pageSize, MatchTeam example) {
		StringBuilder sb = new StringBuilder("from MatchTeam mt where 1=1  ");
		List<Object> parameList = new ArrayList<Object>();
		if(Utility.isNotNull(example.getMatch().getId())){
			sb.append(" and mt.match.id = ? ");
			parameList.add(example.getMatch().getId());
		}
		if(Utility.isEmpty(example.getTeam().getTeamName())){
			sb.append(" and mt.team.teamName = ? ");
			parameList.add(example.getTeam().getTeamName());
		}
		return (Pager<MatchTeam>) queryListPageByHql(sb.toString(), curpage, pageSize, parameList);
	}

	@Override
	public List<MatchTeam> findByTeam(Team team) {
		StringBuilder sb = new StringBuilder("from MatchTeam mt where 1=1  and mt.team.id= ? order by mt.id " );
		List params = new ArrayList();
		params.add(team.getId());
		return (List<MatchTeam>) findByHQL(sb.toString(), params);
	}

	
}
